﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Ninject;
using Ninject.Web;
using Ninject.Web.Mvc.FluentValidation;
using Ninject.Web.Common;
using Cat.Domain.Repositories;
using System.Web.Routing;
using Cat.Domain.Shared;

namespace Cat.Web.Framework.Infrastructure.Factories
{
    public class ControllerFactory : DefaultControllerFactory
    {
        private IKernel kernel;

        public ControllerFactory()
        {
            kernel = new StandardKernel();
            AddBindings();
        }

        protected override IController GetControllerInstance(RequestContext requestContext,
            Type controllerType)
        {

            return controllerType == null
                ? null
                : (IController)kernel.Get(controllerType);
        }

        private void AddBindings()
        {
            // put additional bindings here
            //kernel.Bind<IWorkExperienceRepository>>().To<WorkExperienceRepository>();
            kernel.Bind<ILinkRepository>().To<LinkRepository>().InRequestScope();
            kernel.Bind<IDbContext>().To<SqlServerContext>().InRequestScope();
        }
    }
}
